package com.sjc.consumer.service.impl;

import com.sjc.consumer.dao.TransferDao;
import com.sjc.consumer.service.ITransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("transferServiceCancel")
public class TransferServiceCancel implements ITransferService {
    @Autowired
    private TransferDao transferDao;

    @Transactional
    @Override
    public void transfer(String sourceAcctId, String targetAcctId, double amount) {
        int value = this.transferDao.cancelDecrease(sourceAcctId, amount,amount);
        if (value != 1) {
            throw new IllegalStateException("ERROR!");
        }
        System.out.printf("exec decrease: acct= %s, amount= %7.2f%n", sourceAcctId, amount);
    }
}
